$(() => {
    // 获取area_id
    const token = GetQueryString('token');
    let id = GetQueryString('id');

    $.ajax({
        type: "post",
        url: url,
        data: { "method": "News|news_detail", "id": id },
        dataType: 'json',
        success: function(res) {
            if (res.status == 1) {
                // console.log(res);
                let data = res.data;
                let html = '';
                let date = getDate(data.create_time);

                // 分享
                let shareUrl = domain + "/view/share_headlineDetail.html?id=" + data.id;
                // let shareTitle = data.company_name;
                // let shareImgUrl = data.company_logo;
                let shareTitle = data.title;
                let shareImgUrl = data.poster_thumb;
                let shareDes = data.company_name;
                
                // 分享
                $('.share').on('click', function() {
                    if (isAndroid_ios()) {
                        //安卓  
                        window.android.shareWebMethod(shareUrl, shareTitle, shareDes, shareImgUrl);
                    } else {
                        //ios
                        // window.webkit.messageHandlers.shareWebMethod.postMessage(shareUrl, shareTitle, shareTitle, shareImgUrl);
                        var d={};
                        d.shareUrl=shareUrl;
                        d.title=shareTitle;
                        d.description=shareDes;
                        d.imgUrl=shareImgUrl;
                        window.webkit.messageHandlers.shareWebMethod.postMessage(d);
                    }
                })

                html = `
                <div class="comList">`
                if (data.company_level >= 1) {
                    html += `<a href="./shop_details_company.html?company_id=${data.company_id}&token=${token}" class="comHead">`
                } else {
                    html += `<a href="./shop_details.html?company_id=${data.company_id}&token=${token}" class="comHead">`
                }
                html += `<div class="comHeadLeft">
                            <img class="headImg" src="${data.company_logo == '' ? '../img/user.jpg' : data.company_logo}" alt="${data.company_name}">
                            <div class="headlineTopChild">
                                <p>${data.company_name}</p>`
                if (data.level_logo != '') {
                    html += `<img src="${data.level_logo}" class="userLevel" alt="${data.level_name}"/>`
                }
                html += `</div>
                        </div>
                        <p class="comHeadRight">进店</p>
                    </a>
                    <div class="headline_content">${data.content}</div>
                    <p class="comAddr">浏览量：${data.read_count}
                        <span>${date}</span>
                    </p>
                </div>
                `;
                $('.comLists').html(html);
            } else if (res.status == 2) {
                location.href = "fox://logout";
            } else {
                alert(res.message);
            }
        }
    })

    // 分享下载链接及备案信息底部
    if ($('.downLoad').length) {
        $.ajax({
            type: "post",
            url: url,
            data: { "method": "Api|share_bottom" },
            dataType: 'json',
            success: function(res) {
                if (res.status == 1) {
                    let data = res.data;
                    let html = '';
                    data.download.forEach(item => {
                        html += `
                <li><a href="${item.url}">${item.type_name}</a></li>
                `;
                    })
                    $('.dlLists').html(html);
                    $('.icp_info').html(data.icp_info);
                    $('.other_msg').html(data.other_msg);
                }
            }
        })
    }
})